public class Position {
    /**
    * 坐标参数
    * */
    private int x;
    private int y;
    private int z;

    public Position(int x, int y, int z){
        this.x = x;
        this.y = y;
        this.z = z;
    }
    //用于存储一个String的坐标对象，中间用,隔开
    public Position(String coordinate){
        int []num =new int[3];//保存三个方向的坐标
        int flag=0;
        for (int k = 0; k <2; k++) {
            for (int i = flag; i <coordinate.length(); i++) {
                if(coordinate.substring(i,i+1).equals(",")){
                    num[k] = Integer.parseInt(coordinate.substring(flag,i));
                    flag = i+1;
                    break;
                }
            }
        }
        num[2] = Integer.parseInt(coordinate.substring(flag));
        this.x = num[0];
        this.y = num[1];
        this.z = num[2];
    }

    /**
    * 两点直线距离
    * */
    public  double getDistance(Position p){
        double distanceX = this.getX()-p.getX();
        double distanceY = this.getY()-p.getY();
        double distanceZ = this.getZ()-p.getZ();
        double distance;
        //在一层楼的计算方法
        if(distanceZ==0){
            distance = Math.sqrt(distanceX*distanceX + distanceY*distanceY);
        }
        //如果不在一层楼的计算方法
        else{
            distance = Math.abs(distanceZ)+Math.sqrt((this.getX()-25)*(this.getX()-25)+(this.getY()-25)*(this.getY()-25))+
                    Math.sqrt((p.getX()-25)*(p.getX()-25)+(p.getY()-25)*(p.getY()-25));
        }
        return distance;
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public int getZ() {
        return z;
    }

    public void setZ(int z) {
        this.z = z;
    }

}
